package ar.com.ford.it.fullEconomics.facade;

import java.util.Collection;
import ar.com.ford.it.fullEconomics.exception.FullEconomicsException;
import ar.com.ford.it.fullEconomics.logic.RequestItemLogic;
import ar.com.ford.it.fullEconomics.logic.RequestLogic;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesr01Request;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesr02Requestitm;
import ar.com.ford.it.fullEconomics.struct.RequestFindStruct;
import ar.com.ford.it.fullEconomics.wslx.FullEconomicsWslxUser;

public class RequestFacade {

    /**
     * Crea el request
     * 
     * @param request
     * @param user
     * @return
     * @throws FullEconomicsException
     */
    public Teesr01Request createRequest(Teesr01Request request,
                                        FullEconomicsWslxUser user)
            throws FullEconomicsException {
        RequestLogic logic = new RequestLogic();
        Teesr01Request req = logic.createRequest(request, user);
        return req;
    }

    /**
     * Cierra el request
     * 
     * @param code
     * @param user
     * @throws FullEconomicsException
     */
    public void closeRequest(Integer code, FullEconomicsWslxUser user)
            throws FullEconomicsException {
        RequestLogic logic = new RequestLogic();
        logic.closeRequest(code, user);
    }
    
    /**
     * reabre el request
     * 
     * @param code
     * @param user
     * @throws FullEconomicsException
     */
    public void reopenRequest(Integer code, FullEconomicsWslxUser user)
            throws FullEconomicsException {
        RequestLogic logic = new RequestLogic();
        logic.reopenRequest(code, user);
    }

    /**
     * guarda cambios hechos en el request
     * 
     * @param request
     * @param user
     * @throws FullEconomicsException
     */
    public void updateRequest(Teesr01Request request, FullEconomicsWslxUser user)
            throws FullEconomicsException {
        RequestLogic logic = new RequestLogic();
        logic.updateRequest(request, user);
    }

    /**
     * Borra el request pasado por parametro y sus items
     * 
     * @param request
     * @throws FullEconomicsException
     */
    public void deleteRequest(Teesr01Request request)
            throws FullEconomicsException {
        RequestLogic logic = new RequestLogic();
        logic.deleteRequest(request);
    }

    /**
     * busqueda de reuqests
     * 
     * @param findStruct
     * @return
     * @throws FullEconomicsException
     */
    public Collection<Teesr01Request> findRequests(RequestFindStruct findStruct)
            throws FullEconomicsException {
        RequestLogic logic = new RequestLogic();
        Collection<Teesr01Request> ret = logic.findRequests(findStruct);
        return ret;
    }

    /**
     * crea un request item, debe contener el request al que pertenece
     * 
     * @param item
     * @param user
     * @throws FullEconomicsException
     */
    public void createRequestItem(Teesr02Requestitm item,
                                  FullEconomicsWslxUser user)
            throws FullEconomicsException {

        RequestItemLogic logic = new RequestItemLogic();
        logic.createRequestItem(item, user);

    }

    /**
     * guarda los cambios hechos en un request item
     * 
     * @param item
     * @param user
     * @throws FullEconomicsException
     */
    public void updateRequestItem(Teesr02Requestitm item,
                                  FullEconomicsWslxUser user)
            throws FullEconomicsException {

        RequestItemLogic logic = new RequestItemLogic();
        logic.updateRequestItem(item, user);

    }

    /**
     * busca los items pertencientes al request
     * 
     * @param request
     * @return
     * @throws FullEconomicsException
     */
    public Collection<Teesr02Requestitm> findRequestItems(Teesr01Request request)
            throws FullEconomicsException {

        RequestItemLogic logic = new RequestItemLogic();
        Collection<Teesr02Requestitm> ret = logic.findRequestItems(request);
        return ret;

    }
    
    /**
     * busca los items segun los criterios de busqueda
     * 
     * @param request
     * @return
     * @throws FullEconomicsException
     */
    public Collection<Teesr02Requestitm> findRequestItems(RequestFindStruct findStruct)
            throws FullEconomicsException {

        RequestItemLogic logic = new RequestItemLogic();
        Collection<Teesr02Requestitm> ret = logic.findRequestItems(findStruct);
        return ret;

    }

    /**
     * borra el item pasado por parametro
     * 
     * @param item
     * @throws FullEconomicsException
     */
    public void deleteRequestItem(Teesr02Requestitm item)
            throws FullEconomicsException {
        RequestItemLogic logic = new RequestItemLogic();
        logic.deleteRequestItem(item);
    }
}
